// 字符串转json
String.prototype.deJson = function () {
    try {
        return JSON.parse(this.toString() || "");
    } catch (error) {
        return this.toString();
    }
}
// 补全指定长度的空格
String.prototype.toStringLen = function (len) {
    if (len && this.toString().length < len) {
        let num = len - this.toString().length, str = this.toString();
        for (let index = 0; index < num; index++) {
            str += " ";
        }
        return str;
        //console.log(this.toString(),str);
    }
    return this.toString();
}
// 驼峰转连接字符串
String.prototype.toConString = function () {
    return this.toString().replace(/([A-Z])/g, "_$1").toLowerCase();
}
//脱敏
String.prototype.desensitization = function (len = 5) {
    let str = this.toString();
    if (!str) return "";
    return str.replace(/(\d{3})\d{5}(\d{3})/, '$1****$2');
}
// 判断一个字符串是以指定字符串结尾的
String.prototype.endWith = function (endStr) {
    var d = this.length - endStr.length;
    return (d >= 0 && this.lastIndexOf(endStr) == d);
}
/**
 * 已知前后文 取中间文本
 * @param str 全文
 * @param start 前文
 * @param end 后文
 * @returns 中间文本 || null
 */
String.prototype.takeCenterStr = function (start, end) {
    let str = this.toString();
    if (!str) return null;
    let res = str.match(new RegExp(`${start}(.*?)${end}`))
    return res ? res[1] : null
}